package com.hawthorn.admin.controller.syscompany;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hawthorn.admin.service.syscompany.SysCompanyService;
import com.hawthorn.platform.annotation.MarkLog;
import com.hawthorn.platform.exception.BizCode;
import com.hawthorn.platform.utils.common.MyUtil;
import com.hawthorn.platform.utils.iassert.AssertMyUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Map;


/**
 * <p>todo 公司维护 controller</p>
 * @author: wcz
 * @created: 2022-07-01
 * @version v1.0.2
 */
@Api(tags = {"admin-syscompany"})
@RestController
@RequestMapping("/syscompany/")
public class SysCompanyController
{
  @Resource
  private SysCompanyService companyService;

  /**
   * <p>todo 查询公司信息</p >
   * @author: WCZ
   * @date: 2022/6/21 20:06
   * @version: 1.0.1
   */
  @ApiOperation(value = "查询->全部公司信息", notes = "查询全部公司信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "查询条件参数", dataTypeClass = String.class)
  })
  @PostMapping(value = "/findCompanies")
  public IPage<Map<String, Object>> findCompanies(@RequestBody String params)
  {
    Page<Map<String, Object>> page = new Page<>();
    String conditions = MyUtil.getConditionsWhere(params, page);
    return companyService.findCompanies(page, conditions);
  }

  /**
   * <p>todo 新增</p >
   * @author: WCZ
   * @date: 2022/6/22 10:30
   * @version: 1.0.1
   */
  @ApiOperation(value = "新增->新增公司信息", notes = "新增公司信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "保存参数", dataTypeClass = Map.class)
  })
  @PostMapping(value = "/saveCompany")
  @MarkLog(value = "新增公司-[{0}]", param = "cname")
  public Map<String, Object> saveCompany(@RequestBody Map<String, Object> params)
  {
    return companyService.saveCompany(params);
  }

  /**
   * <p>todo 编辑</p >
   * @author: WCZ
   * @date: 2022/6/22 13:25
   * @version: 1.0.1
   */
  @ApiOperation(value = "编辑 ->编辑用户信息", notes = "编辑用户信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
      @ApiImplicitParam(name = "param", value = "更新参数", dataTypeClass = Map.class)
  })
  @PutMapping(value = "/updateCompany/{id}")
  @MarkLog(value = "更新公司-[{0}]", param = "cname")
  public Map<String, Object> updateCompany(@PathVariable Long id, @RequestBody Map<String, Object> params)
  {
    return companyService.updateCompany(id, params);
  }

  /**
   * <p>todo 导出</p >
   * @author: WCZ
   * @date: 2022/6/21 20:06
   * @version: 1.0.1
   */
  @ApiOperation(value = "导出->导出公司信息", notes = "导出公司信息")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "response", value = "response", dataTypeClass = HttpServletResponse.class),
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/exportCompanyData")
  public void exportCompanyData(HttpServletResponse response, @RequestBody Map<String, Object> param) throws IOException
  {
    AssertMyUtil.notNull(param, BizCode.VARIABLE_NOT_EMPTY, "param");
    companyService.exportCompanyData(response, "公司信息导出", param);

  }

  /**
   * <p>todo 修改状态</p >
   * @author: WCZ
   * @date: 2022/6/23 14:02
   * @version: 1.0.1
   */
  @ApiOperation(value = "修改->状态", notes = "修改状态")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "id", value = "主键", dataTypeClass = Long.class),
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/changeStatus/{id}")
  @MarkLog(value = "修改公司状态-[{0}]", param = "cname")
  public Map<String, Object> changeStatus(@PathVariable Long id, @RequestBody String params)
  {
    return companyService.changeStatus(id, params);
  }

  /**
   * <p>todo 添加公司部门</p>
   * @author: gaoyuan
   * @date: 2023/1/6 10:51
   * @version: 1.0.1
   */
  @ApiOperation(value = "添加->公司部门", notes = "添加公司部门")
  @ApiImplicitParams({
      @ApiImplicitParam(name = "params", value = "params", dataTypeClass = String.class)
  })
  @PostMapping(value = "/saveComDept")
  @MarkLog(value = "添加公司部门-[{0}]", param = "params")
  public Map<String, Object> saveComDept(@RequestBody Map<String, Object> params)
  {
    return companyService.saveComDept(params);
  }
}
